package com.qiudaozhang.controller;

import com.qiudaozhang.dto.ResponseCode;
import com.qiudaozhang.model.BasicsParameter;
import com.qiudaozhang.service.BasicsParameterService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.persistence.Basic;
import java.time.LocalDate;

@Controller
@RequestMapping("basics")
public class BasicsParameterController {

    @Autowired
    private BasicsParameterService basicsParameterService;


    @RequestMapping("to/list")
    public String  toList(){
        return "basics/list";
    }
    @RequestMapping("to/add")
    public String  toAdd(){
        return "basics/add";
    }
    @RequestMapping("to/see")
    public String  toSee(@Param("id")Long id,Model model){
        BasicsParameter b =basicsParameterService.queryById(id);
        model.addAttribute("bas", b);
        return "basics/see";
    }
    @RequestMapping("add")
    public String  add(BasicsParameter basicsParameter){
        basicsParameterService.add(basicsParameter);
        return "redirect:to/list";
    }
    @RequestMapping("to/modify")
    public String toModify(@Param("id")Long id, Model model){
        BasicsParameter b =basicsParameterService.queryById(id);
        model.addAttribute("bas", b);
        return "basics/modify";
    }
    @RequestMapping("modify")
    public String modify(BasicsParameter b){
        basicsParameterService.modify(b);
        return "redirect:to/list";
    }
    @RequestMapping("list")
    @ResponseBody
    public ResponseCode  list(){
        ResponseCode code = basicsParameterService.query();
        return code;
    }
    @RequestMapping("del/{id}")
    @ResponseBody
    public ResponseCode  del(@PathVariable("id") Long id){
        ResponseCode code = basicsParameterService.del(id);
        return code;
    }
}
